package com.chixing.util;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: wtl
 * @Date: 2021/10/17/21:23
 * @Description:
 */
public class DateUtil {
    //年月日时分秒：yyyy-MM-dd HH:mm:ss pattern （格式）
    public static final String DATE_PATTEN_YMDHMS = "yyyy-MM-dd HH:mm:ss";
    //		年月日时分：yyyy-MM-dd HH:mm
    public static final String DATE_PATTEN_YMDHM = "yyyy-MM-dd HH:mm";
    //		时分秒：HH:mm:ss
    public static final String DATE_PATTEN_HMS = "HH:mm:ss";
    //		时分：HH:mm
    public static final String DATE_PATTEN_HM = "HH:mm";
    public static final String DATE_PATTEN_YMD = "yyyy-MM-dd";
    public static final String PATTERN_YMDHMS = "yyyyMMdd";


    // Date 转换成 String
    public static String dateToString(Date date, String pattern){
        DateFormat dateFormat = new SimpleDateFormat(pattern);
        return dateFormat.format(date);
    }
    // String 转换成 Date
    public static Date stringToDate(String dateStr,String pattern){
        DateFormat dateFormat = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = dateFormat.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
